package edu.cdnu.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import edu.cdnu.dao.NoticeDao;
import edu.cdnu.pojo.NoticePojo;
import edu.cdnu.service.NoticeService;

@Service
public class NoticeServiceImpl implements NoticeService {
	
	@Autowired
	private NoticeDao noticeDao;

	@Override
	public List<NoticePojo> selectNoticeListByCourseIdOrClassId(Integer courseId, Integer classId) {
		// 不能同时为空
		if(courseId != null || classId != null) {
			return noticeDao.selectNoticeListByCourseIdOrClassId(courseId, classId);
		}
		return null;
	}

	@Override
	public void addOrUpdateNotice(NoticePojo noticePojo) {
		if(noticePojo == null) {
			return ;
		}else if(noticePojo.getId() == null) {
			// 新增
			noticeDao.insertNotice(noticePojo);
		}else {
			noticeDao.updateNoticeByNoticePojo(noticePojo);
		}
	}

	@Override
	public void deleteNoticeByNoticeId(int noticeId) {
		noticeDao.deleteNoticeByNoticeId(noticeId);
	}

	@Override
	public List<NoticePojo> selectNoticeByClassIdListAndDayNumber(List<Integer> classIdList, int day) {
		if(classIdList==null||classIdList.size()<1) {
			return null;
		}
		return noticeDao.selectNoticeByClassIdListAndDayNumber(classIdList, day);
	}

	@Override
	public List<NoticePojo> selectNoticeByCourseIdListAndDayNumber(List<Integer> courseIdList, int day) {
		if(courseIdList==null||courseIdList.size()<1) {
			return null;
		}
		return noticeDao.selectNoticeByCourseIdListAndDayNumber(courseIdList, day);
	}

	
}
